a=int(input("Введите четырех зачное натуральное число"))
if a>999 and a<10000 :
    s=0
    vivod=0
    ed=a%10
    des=(a%100-ed)//10
    sot=a//100-(a//1000)*10
    tis=a//1000
    for i in range(1, ed+1):
        if (ed%i==0):
            s+=1
    if s == 2 and ed>vivod :
        vivod=ed
    s=0
    for i in range(1, ed+des*10+1):
        if ((ed+des*10)%i==0):
            s+=1
    if s == 2 and ed+des*10>vivod :
        vivod=ed+des*10
    s=0
    for i in range(1, ed+des*10+sot*100+1):
        if (a%i==0):
            s+=1
    if s == 2 and ed + des * 10 +sot*100 > vivod:
        vivod = ed + des * 10+sot*100
    s=0
    for i in range(1,  a+1):
        if (a%i==0):
            s+=1
    if s == 2 and a > vivod:
        vivod = a
    s=0
    for i in range(1, des+1):
        if (des%i==0):
            s+=1
    if s == 2 and des > vivod:
        vivod = des
    s=0
    for i in range(1, des+sot*10+1):
        if ((des+sot*10)%i==0):
            s+=1
    if s == 2 and des > vivod:
        vivod = des+sot*10
    s=0
    for i in range(1, des+sot*10+tis*100+1):
        if ((des+sot*10+tis*100)%i==0):
            s+=1
    if s == 2 and des+sot*10+tis*100 > vivod:
        vivod = des+sot*10+tis*100
    s=0
    for i in range(1, sot+1):
        if (sot%i==0):
            s+=1
    if s == 2 and sot > vivod:
        vivod = sot
    s=0
    for i in range(1, sot+tis*10+1):
        if ((sot+tis*10)%i==0):
            s+=1
    if s == 2 and sot+tis*10 > vivod:
        vivod = sot+tis*10
    s=0
    for i in range(1, sot+1):
        if (sot%i==0):
            s+=1
    if s == 2 and tis > vivod:
        vivod = tis
    s=0
    print(vivod)
else :
    print("ERROR")